package main

import (
	"fmt"
	"net"
)

func main() {
	listen, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.IPv4(0, 0, 0, 0), Port: 30000})

	if err != nil {
		fmt.Println("listen err", err)
		return
	}
	defer listen.Close()
	for {
		var data [1024]byte
		n, addr, err := listen.ReadFromUDP(data[:])
		if err != nil {
			fmt.Println("read udp err", err)
			continue
		}
		fmt.Printf("data:%v addr %v", string(data[:n]), addr)
		_, err = listen.WriteToUDP([]byte("server reply"), addr)
		if err != nil {
			fmt.Println("writ to add err ", err)
			continue
		}
	}
}
